{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Validating Dürer's Magic Square\n",
    "\n",
    "Albrecht Dürer was an artist and mathematician who created an engraving of a [magic square](https://mathworld.wolfram.com/DuerersMagicSquare.html), where lots of bits all add up to the same thing.  Each row, column, quadrant, corners, etc. all add up to 34.\n",
    "\n",
    "At the bottom, you see 15 and 14, signifying the year it was engraved (1514) as well as 4 and 1, standing for D and A, the creator's initials.\n",
    "\n",
    "You're going to validate that everything does, in fact, add up."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[16,  3,  2, 13],\n",
       "       [ 5, 10, 11,  8],\n",
       "       [ 9,  6,  7, 12],\n",
       "       [ 4, 15, 14,  1]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "square = np.array(\n",
    "    [\n",
    "        [16, 3, 2, 13],\n",
    "        [5, 10, 11, 8],\n",
    "        [9, 6, 7, 12],\n",
    "        [4, 15, 14, 1],\n",
    "    ]\n",
    ")\n",
    "square"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All assertions passed!\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    assert square[i, :].sum() == 34\n",
    "    assert square[:, i].sum() == 34\n",
    "\n",
    "assert square[:2, :2].sum() == 34\n",
    "assert square[2:, :2].sum() == 34\n",
    "assert square[:2, 2:].sum() == 34\n",
    "assert square[2:, 2:].sum() == 34\n",
    "\n",
    "print(\"All assertions passed!\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
